package com.yyy.dm.listener.orderPay;

import com.yyy.dm.feign.DMOrderFeign;
import com.yyy.dm.feign.DMSchedulerSeatFeign;
import com.yyy.dm.order.DMOrder;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@RabbitListener(queues = "dm_order_dlx_queue")
public class OrderPayListener {

    @Resource
    private DMOrderFeign dmOrderFeign;
    @Resource
    private DMSchedulerSeatFeign dmSchedulerSeatFeign;

    @RabbitHandler
    public void rollbackOrder(DMOrder dmOrder) {
        //根据dmorder里的东西 判断订单状态 是否修改  不然就回滚
        if (dmOrderFeign.findOrderTypeById(dmOrder.getId()) != 2) {
            //修改订单状态 释放座位
            dmSchedulerSeatFeign.rollbackSchedulerSeat(dmOrder.getOrderNo());
            dmOrderFeign.updateOrderStatuePay(dmOrder.getOrderNo());
        }
    }

}
